package com.itheima.tanhua.controller;

import com.alibaba.fastjson.JSON;
import com.itheima.tanhua.dto.AnswersDto;
import com.itheima.tanhua.service.TestSoulService;
import com.itheima.tanhua.vo.PersonalityVo;
import com.itheima.tanhua.vo.QuestionnaireVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Lff
 * @date 2022/4/8
 * <p>
 * 测灵魂
 */
@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    /**
     * 测灵魂-提交问卷
     *
     * @param
     * @return 报告id
     */
    @PostMapping
    public ResponseEntity subTestSoul(@RequestBody Map map) {
        //提交问卷
        List<AnswersDto> str = (List<AnswersDto>) map.get("answers");
        System.out.println(str);
        String id = testSoulService.subTestSoul(str);
        //返回值报告id
        return ResponseEntity.ok(id);
    }


    /**
     * 测灵魂-问卷列表
     *
     * @return
     */
    @GetMapping
    public ResponseEntity getTestSoulQuestionnaires() {
        List<QuestionnaireVo> results = testSoulService.getQuestionnairesList();
        return ResponseEntity.ok(results);
    }

    /**
     * 获取报告
     */
    @GetMapping("/report/{id}")
    public ResponseEntity getReport(@PathVariable Long id) {
        PersonalityVo report = testSoulService.getReport(id);
        return ResponseEntity.ok(report);
    }

}
